<template>
  <div class="app-container p-rel">
    <div class="container-title">查询</div>
    <form-edit class="p-abs" :detailForm="detailForm" :isEdit="isEdit" @submitForm="submitForm" :editVisible.sync="editVisible" v-if="editVisible"></form-edit>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">

        <el-col :lg="8" :xl="8">
          <el-form-item label="报告时间" prop="heathCheckDate">
            <el-date-picker
              v-model="checkDateTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :lg="8" :xl="6">
          <el-form-item label="姓名" prop="realName">
            <el-input
              v-model="queryParams.realName"
              placeholder="请输入姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="工作岗位" prop="postName">
            <el-input
              v-model="queryParams.postName"
              placeholder="请输入工作岗位"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="联系电话" prop="mobile">
            <el-input
              v-model="queryParams.mobile"
              placeholder="请输入联系电话"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="身份证号" prop="idcardNo">
            <el-input
              v-model="queryParams.idcardNo"
              placeholder="请输入身份证号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>

        <el-col :lg="8" :xl="6">
            <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
            <el-button icon="" size="" @click="resetQuery">重置</el-button>
            <el-button type="warning" icon="" size="" @click="openPersonnelHeath">同步体检信息</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-dialog
      title="同步入参筛选条件"
      :visible.sync="heathDialog"
      width="30%"
    >
      <el-form ref="heathForm" :model="heathForm" label-width="80px">
        <el-form-item label="页数">
          <el-input-number v-model="heathForm.page"  :min="1"  label="页数"></el-input-number>
        </el-form-item>
        <el-form-item label="页数大小">
          <el-input-number v-model="heathForm.size"  :min="1"  label="页数大小"></el-input-number>
        </el-form-item>
        <el-form-item label="机构名称">
          <el-input v-model="heathForm.organName"  :min="1"  label="机构名称"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="heathForm.realName"  :min="1"  label="姓名"></el-input>
        </el-form-item>
        <el-form-item label="体检状态">
          <el-select v-model="heathForm.heathStatus" clearable  placeholder="请选择体检状态" style="width: 100%;" >
            <el-option
              v-for="dict in heathStatusOption"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最小id值">
          <el-input-number v-model="heathForm.minId"  :min="1"  label="最小id值"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="cancelDialog">取 消</el-button>
    <el-button type="primary" @click="syncPersonnelHeath">确 定</el-button>
      </span>
    </el-dialog>


    <el-table v-loading="loading" :data="hpersonnelHeathList" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" align="center" label="序号"/>
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="报告时间" align="center" prop="heathCheckDate" />
      <el-table-column label="主检建议" align="center" prop="heathMhkAdv" />
      <el-table-column label="体检结果" align="center" prop="heathBhkRst" />
      <el-table-column label="体检结论" align="center" prop="heathVerDict" />
      <el-table-column label="体检状态" align="center" prop="heathStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.heath_status" :value="scope.row.heathStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="realName" />
      <el-table-column label="工作岗位" align="center" prop="postName" />
      <el-table-column label="联系电话" align="center" prop="mobile" />
      <el-table-column label="身份证号" align="center" prop="idcardNo" />
      <el-table-column label="机构名称" align="center" prop="organName" />
      <el-table-column label="机构编码" align="center" prop="organCode" />
      <el-table-column label="企业统一信用码" align="center" prop="creditCode"/>
      <el-table-column label="机构子类型编码" align="center" prop="organSubType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.organ_sub_type" :value="scope.row.organSubType"/>
        </template>
      </el-table-column>
      <el-table-column label="机构地址" align="center" prop="organAddress" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row,2)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >查看体检详情</el-button>
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,1)"
            v-hasPermi="['health:hpersonnelHeath:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['health:hpersonnelHeath:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

</template>

<script>
import { listHpersonnelHeath, getHpersonnelHeath, delHpersonnelHeath, addHpersonnelHeath, updateHpersonnelHeath, syncPersonnelHeath } from "@/api/health/hpersonnelHeath";
import formEdit from './editFrom.vue'
export default {
  name: "HpersonnelHeath",
  components:{ formEdit },
  dicts: ['heath_status','organ_sub_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 体检信息表格数据
      hpersonnelHeathList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        heathCheckDate: null,
        heathMhkAdv: null,
        heathBhkRst: null,
        heathVerDict: null,
        heathStatus: null,
        realName: null,
        postName: null,
        mobile: null,
        idcardNo: null,
        organName: null,
        organCode: null,
        creditCode: null,
        organSubType: null,
        organAddress: null,
        checkStartDateTime: null,
        checkEndDateTime: null,
      },
      checkDateTime: [],
      heathStatusOption: [
        {
          label: "合格",
          value: 1
        },
        {
          label: "不合格",
          value: 2
        },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailForm:{},
      isEdit:false,
      editVisible:false,
      heathForm:{
        page: 1,
        size: 10,
        heathStatus: null
      },
      heathDialog: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询体检信息列表 */
    getList() {
      this.loading = true;
      console.log("this.checkDateTime", this.checkDateTime)
      if (this.checkDateTime){
        this.queryParams.checkStartDateTime = this.checkDateTime[0]
        this.queryParams.checkEndDateTime = this.checkDateTime[1]
        console.log('this.queryParams.checkStartDateTime', this.queryParams.checkStartDateTime)
      }else {
        this.queryParams.checkStartDateTime = null
        this.queryParams.checkEndDateTime = null
      }
      listHpersonnelHeath(this.queryParams).then(response => {
        this.hpersonnelHeathList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        heathCheckDate: null,
        heathMhkAdv: null,
        heathBhkRst: null,
        heathVerDict: null,
        heathStatus: null,
        realName: null,
        postName: null,
        mobile: null,
        idcardNo: null,
        organName: null,
        organCode: null,
        creditCode: null,
        organSubType: null,
        organAddress: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.checkDateTime = []
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {}
      this.isEdit = false
      this.editVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      // this.reset();
      const id = row.id || this.ids
      getHpersonnelHeath(id).then(response => {
        this.detailForm = response.data
        if(type == 1){
          this.isEdit = true
        }else{ // 查看
          this.isEdit = false
        }
        this.editVisible = true

      });
    },
    /** 提交按钮 */
    submitForm(form,id) {
    if (id != null) {
      updateHpersonnelHeath(form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.editVisible = false;
        this.getList();
      });
    } else {
      addHpersonnelHeath(form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.editVisible = false;
        this.getList();
      });
    }
    },
    syncPersonnelHeath(){
      syncPersonnelHeath(this.heathForm).then(response => {
        this.$modal.msgSuccess("同步成功");
        this.heathDialog = false
        this.getList();
      });
    },
    cancelDialog(){
      this.heathDialog = false
    },
    openPersonnelHeath(){
      this.heathDialog = true
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除体检信息编号为"' + ids + '"的数据项？').then(function() {
        return delHpersonnelHeath(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('health/hpersonnelHeath/export', {
        ...this.queryParams
      }, `hpersonnelHeath_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
